package com.jinan.wsstudy;

import com.alibaba.fastjson2.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@EnableScheduling
@Component
public class WebSocketScheduled {
    @Autowired
    private WebSocket webSocket;

    @Scheduled(cron = "0/15 * * * * ?")
    public void heartbeat() {
        Student student = new Student();
        student.setId(1);
        student.setStudenName("纷纷");
        student.setStudentNo("0001");
        List<Student> list = new ArrayList<>();
        list.add(student);
        //
        HashMap map = new HashMap();
        map.put("num", 1);
        map.put("list", list);
        webSocket.sendAllMessage("有3条未上传报告" + JSON.toJSONString(map));
    }
}
